<?php
namespace Apipad\Controller;

use Think\Controller;

//仓库库位
class UserKuerpWarehouseLocationController extends UserWarehouseController
{

    //添加前置
    function _before_add(){
        if(IS_POST){
            $model = D(CONTROLLER_NAME);
            if($_POST['loc_name']=="undefined" || empty($_POST['loc_name'])){
                $this->ajaxErrReturn('请输入库位名称');
            }
            $wdata['wh_id'] = I('wh_id');
            $wdata['loc_name'] = I('loc_name');
            $count = $model->where($wdata)->count();
            if($count>0){
                $this->ajaxErrReturn('同名库位已存在');
            }
            //验证是否上传了库位图片
            $pic= I('pic');
            if(empty($pic)){
              $_POST['pic']='https://wages-zymaimai.oss-cn-beijing.aliyuncs.com/2023/04/18/643dffd0e6f97.png';
            }
        }
    }

    //编辑前置
    function _before_edit(){
        if(IS_POST){
            $model = D(CONTROLLER_NAME);
            $wdata['id'] = array('neq',I('id'));
            $wdata['wh_id'] = I('wh_id');
            $wdata['loc_name'] = I('loc_name');
            $count = $model->where($wdata)->count();
            if($count>0){
                $this->ajaxErrReturn('同名库位已存在');
            }
            //验证是否上传了库位图片
            $pic= I('pic');
            if(empty($pic)){
              $_POST['pic']='https://wages-zymaimai.oss-cn-beijing.aliyuncs.com/2023/04/18/643dffd0e6f97.png';
            }
        }
    }

    //删除
    function fdel(){
        $kwlp_model = D('UserKuerpWarehouseLocation');
        $kwlp_wdata['uid'] = UID;
        $kwlp_wdata['id'] = I('id');
        $vo = $kwlp_model->where($kwlp_wdata)->find();
        if(!$vo){
            $this->ajaxErrReturn('数据不存在');
        }
        //启用事务
        $kwlp_model->startTrans();
        $result = $kwlp_model->fdel(I('id'));
        if($result['status']){
            //事务提交
            $kwlp_model->commit();
            $this->ajaxSucReturn('删除成功');
        }else{
            $this->ajaxErrReturn($result['msg']);
        }
    }

    
}

?>